package com.oodso.say.ui;

import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;
import android.widget.Toast;

import com.oodso.say.R;
import com.oodso.say.base.SayActivity;
import com.oodso.say.ui.regist.LoginActivity;
import com.oodso.say.utils.JumperUtils;
import com.oodso.say.utils.SignoutUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends SayActivity {
    @BindView(R.id.tv_login)
    TextView tvLogin;
    private long exitTime = 0;

    @Override
    protected void initUI() {
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void initData() {

    }


    //点击返回键提示是否退出应用
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_BACK &&
                event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(getApplicationContext(), "再按一次退出程序",
                        Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                SignoutUtils.getInstance().exit();
//                System.exit(0);
//                Process.killProcess(Process.myPid());
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @OnClick(R.id.tv_login)
    public void onViewClicked() {
        JumperUtils.JumpTo(MainActivity.this, LoginActivity.class);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
